home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / fuzz.arc / SIMIL.ASM < prev   
Assembly Source File  |  1991-04-28  |  3KB  |  211 lines

  1.     TITLE     SIMIL.ASM   written by John W. Ratcliff and David E. Metzener
  2.     
  3. ; November 10, 1987
  4. ; Uses the Ratcliff/Obershelp pattern recognition algorithm
  5. ; This program provides a new function to C on an 8086 based machine.
  6. ; The function SIMIL returns a percentage value corresponding to how
  7. ; alike any two strings are.  Be certain to upper case the two strings
  8. ; passed if you are not concerned about case sensitivity.
  9. ; NOTE: This routine is for SMALL model only.  As an exercise for
  10. ; the student, feel free to convert it to LARGE.
  11.  
  12.  
  13. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  14. _TEXT    ENDS
  15. CONST    SEGMENT WORD PUBLIC 'CONST'
  16. CONST    ENDS
  17. _BSS    SEGMENT    WORD PUBLIC 'BSS'
  18. _BSS    ENDS
  19. _DATA    SEGMENT    WORD PUBLIC 'DATA'
  20. _DATA    ENDS
  21. DGROUP    GROUP CONST,_BSS,_DATA
  22.     ASSUME    CS:_TEXT, DS:DGROUP, SS:DGROUP, ES:DGROUP
  23.     
  24. _DATA    SEGMENT
  25.  
  26. ststr1L    dw    25 dup (?)
  27. ststr1R    dw    25 dup (?)
  28. ststr2L    dw    25 dup (?)
  29. ststr2R    dw    25 dup (?)
  30. stcknum    dw    ?
  31. score    dw    ?
  32. total    dw    ?
  33. cl1    dw    ?
  34. cr1    dw    ?
  35. cl2    dw    ?
  36. cr2    dw    ?
  37. s2ed    dw    ?
  38.  
  39. _DATA ENDS
  40.  
  41.     public _simil
  42.     
  43. _TEXT    SEGMENT
  44.  
  45. _simil    proc    near
  46.     push    bp
  47.     mov    bp,sp
  48.     push    es
  49.     mov    ax,ds
  50.     mov    es,ax
  51.     xor    ax,ax
  52.     mov    score,ax
  53.     mov    stcknum,ax
  54.     mov    si,[bp+4]
  55.     mov    di,[bp+6]
  56.     cmp    [si],al
  57.     je    strerr
  58.     cmp    [di],al
  59.     jne    docmp
  60. strerr:    jmp    donit
  61. docmp:    push    di
  62.     push    si
  63.     xor    al,al
  64.     cld
  65.     mov    cx,-1
  66.     repnz    scasb
  67.     dec    di
  68.     mov    bp,di
  69.     pop    di
  70.     repnz    scasb
  71.     not    cx
  72.     sub    cx,2
  73.     mov    total,cx
  74.     dec    di
  75.     dec    di
  76.     mov    bx,di
  77.     pop    di
  78.     call    pushst
  79. main:    cmp    stcknum,0
  80.     je    done
  81.     call    popst
  82.     call    compare
  83.     cmp    dx,0
  84.     je    main
  85.     shl    dx,1
  86.     add    score,dx
  87.     mov    bp,stcknum
  88.     shl    bp,1
  89.     mov    si,[ststr1l+bp]
  90.     mov    bx,cl1
  91.     mov    di,[ststr2l+bp]
  92.     mov    cx,cl2
  93.     mov    ax,[ststr1r+bp]
  94.     mov    cl1,ax
  95.     mov    ax,[ststr2r+bp]
  96.     mov    cl2,ax
  97.     mov    bp,cx
  98.     cmp    bx,si
  99.     je    chrght
  100.     cmp    bp,di
  101.     je    chrght
  102.     dec    bx
  103.     dec    bp
  104.     cmp    bx,si
  105.     jne    pushit
  106.     cmp    bp,di
  107.     je    chrght
  108. pushit:    call    pushst
  109. chrght:    mov    si,cr1
  110.     mov    bx,cl1
  111.     mov    di,cr2
  112.     mov    bp,cl2
  113.     cmp    si,bx
  114.     je    main
  115.     cmp    di,bp
  116.     je    main
  117.     inc    si
  118.     inc    di
  119.     cmp    bx,si
  120.     jne    push2
  121.     cmp    bp,di
  122.     je    main
  123. push2:    call    pushst
  124.     jmp    short main
  125. done:    mov    ax,score
  126.     mov    cx,100
  127.     mul    cx
  128.     mov    cx,total
  129.     div    cx
  130. donit:    pop    es
  131.     pop    bp
  132.     ret
  133. _simil    endp
  134.  
  135. compare    proc    near
  136.     mov    s2ed,bp
  137.     xor    dx,dx
  138. forl3:    push    di
  139. forl4:    push    di
  140.     push    si
  141.     mov    cx,s2ed
  142.     sub    cx,di
  143.     inc    cx
  144.     push    cx
  145.     repz    cmpsb
  146.     jz    equal
  147.     inc    cx
  148. equal:    pop    ax
  149.     sub    ax,cx
  150.     jnz    newmax
  151.     pop    si
  152.     pop    di
  153. reent:    inc    di
  154. reent2:    cmp    di,bp
  155.     jle    forl4
  156.     pop    di
  157.     inc    si
  158.     cmp    si,bx
  159.     jle    forl3
  160.     ret
  161.     
  162. newmax:    cmp    ax,dx
  163.     jg    newmx2
  164.     pop    si
  165.     pop    di
  166.     add    di,ax
  167.     jmp    short reent2
  168. newmx2:    pop    si
  169.     pop    di
  170.     mov    cl1,si
  171.     mov    cl2,di
  172.     mov    cx,ax
  173.     sub    ax,dx
  174.     sub    bx,ax
  175.     sub    bp,ax
  176.     mov    dx,cx
  177.     dec    cx
  178.     add    di,cx
  179.     mov    cr2,di
  180.     add    cx,si
  181.     mov    cr1,cx
  182.     jmp    short reent
  183. compare    endp
  184.  
  185. pushst    proc    near
  186.     mov    cx,bp
  187.     mov    bp,stcknum
  188.     shl    bp,1
  189.     mov    [bp+ststr1l],si
  190.     mov    [bp+ststr1r],bx
  191.     mov    [bp+ststr2l],di
  192.     mov    [bp+ststr2r],cx
  193.     inc    stcknum
  194.     mov    bp,cx
  195.     ret
  196. pushst    endp
  197.  
  198. popst    proc    near
  199.     dec    stcknum
  200.     mov    bp,stcknum
  201.     shl    bp,1
  202.     mov    si,[bp+ststr1l]
  203.     mov    bx,[bp+ststr1r]
  204.     mov    di,[bp+ststr2l]
  205.     mov    bp,[bp+ststr2r]
  206.     ret
  207. popst    endp
  208.  
  209. _TEXT    ENDS
  210.     END
  211.